|
|
|
| data source you want to open. You can use an ODBC connection string if youre using the ODBC provider; otherwise, you use the OLE DB connection string to specify the provider you want. |
|
|
|
|
|
|
Examples Filename: Ado.bas |
|
|
|
|
|
|
|
|
Heres a function named DataOpen() that opens a connection to a data source. You can call this from the Form_Load() of your first form or from Sub Main(): |
|
|
|
 |
|
|
|
|
Public Function DataOpen(oConn As Connection) As Boolean
On Error GoTo Open_EH
oConn.CursorLocation = adUseClient
' Set the connection string by calling
' a function. oConn.ConnectionString = ConnectString()
' Set the mode of the connection
oConn.Mode = adModeReadWrite
' Open the Connection oConn.Open
DataOpen = True
Exit Function
Open_EH:
Call ErrorHandler(goConn)
DataOpen = False
Exit Function
End Function |
|
|
|
|
|
|
|
|
After setting the CursorLocation, ConnectionString, and Mode properties, you need to use the Open method to open a connection to the data source. You should always use error handling when attempting to open a connection to a databasethe database might not be available, the network might be down, or 20 million other things could be wrong that can trigger an error when youre attempting to open a connection to the database. |
|
|
|
|
|